<template>
    <div>
        <el-row>
                <el-form ref="addRef" :model="addForm" label-width="80px">
                 <el-col :span="18">   
                     <el-form-item label="书名" prop="bookname">
                        <el-input v-model="addForm.bookname"></el-input>
                    </el-form-item>
                    <el-form-item label="作品分类" prop="sort">
                        <el-select v-model="addForm.sort" placeholder="请选择作品分类">
                            <el-option label="仙侠" value="仙侠"></el-option>
                            <el-option label="武侠" value="武侠"></el-option>
                            <el-option label="玄幻" value="玄幻"></el-option>
                            <el-option label="奇幻" value="奇幻"></el-option>
                            <el-option label="历史" value="历史"></el-option>
                            <el-option label="军事" value="军事"></el-option>
                            <el-option label="科幻" value="科幻"></el-option>
                            <el-option label="灵异" value="灵异"></el-option>
                        </el-select>
                    </el-form-item>
                    </el-col>
                    <el-col :span="19">
                    <el-form-item label="书籍简介" prop="explain">
                        <el-input type="textarea" v-model="addForm.explain" resize="none" :autosize="{ minRows: 6, maxRows: 8}"></el-input>                   
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">立即创建</el-button>
                        <el-button>取消</el-button>
                    </el-form-item>
                 </el-col>
                </el-form>       
        </el-row>
    </div>
</template> 

<script>
export default {
    data() {
        return {
            addForm:{
                bookname:'',
                explain:'',
                sort:'',
                writername:window.sessionStorage.getItem("writerName"),
                writerid:window.sessionStorage.getItem('writerId')
            },
            
        }
    },

    methods: {
        async onSubmit(){
            //console.log(this.addForm)
            let addForm = this.addForm;
            const {data:res} = await this.$http.post("/books/add",{bookname:this.addForm.bookname,explain:this.addForm.explain,sort:this.addForm.sort,
            writerid:this.addForm.writerid,writername:this.addForm.writername});
            //console.log(res); 
            if(res.status != 200) return this.$message.error("添加失败");
            this.$message.success("添加成功");
            this.$refs.addRef.resetFields()
            this.$router.push('/writerBooks')
            //console.log(writerid);


        }
    },
}
</script>

<style lang="less" scoped>
    .el-row{
        top: 40px;
        left: 38px;
    }
</style>